﻿using ConfExpert.Forms.Base;
using ConfExpert.Utility;
using DevExpress.XtraCharts;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace ConfExpert.Forms.Sistem
{
    public partial class WhosOnline2 : XForm
    {
        public WhosOnline2()
        {
            InitializeComponent();
        }

        DataTable dt;
        private void WhosOnline2_Load(object sender, EventArgs e)
        {
            gle.Edit.Assign(RI(Rp.V_User));
            gle.EditValueChanged += Gle_EditValueChanged;

            if (!ds.Tables.Contains("aktif"))
            {
                dt = new DataTable("aktif");
                dt.Columns.Add("Zaman", typeof(DateTime));
                dt.Columns.Add("Adet", typeof(int));
                ds.Tables.Add(dt);
            }

            chartControl1.DataSource = new BindingSource(ds, "aktif");
            chartControl1.RefreshDataOnRepaint = false;
            chartControl1.CacheToMemory = true;

            DateTime now = DateTime.Now;
            beyaz = new ConstantLine(now.ToShortTimeString(), now); //new DateTime(1900, 1, 1, now.Hour, now.Minute, 0).AddMinutes(2));
            beyaz.LineStyle.DashStyle = DevExpress.XtraCharts.DashStyle.DashDot;
            beyaz.LineStyle.Thickness = 2;
            beyaz.Color = Color.BlueViolet;
            ((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).AxisY.ConstantLines.Add(beyaz);
            ((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).EnableAxisXScrolling =
                ((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).EnableAxisXZooming =
            ((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).EnableAxisYScrolling =
                ((DevExpress.XtraCharts.XYDiagram)(chartControl1.Diagram)).EnableAxisYZooming = false;

            //Rfrsh(0);
        }

        private void Gle_EditValueChanged(object sender, EventArgs e)
        {
            int UserId = intParse(gle.EditValue);
            Rfrsh(UserId);
        }

        private void Rfrsh(int UserId)
        {
            GetDetails("aktif", "GetUserConnection", UserId);
            ((DevExpress.XtraCharts.XYDiagram)chartControl1.Diagram).AxisY.VisualRange.MaxValue = DateTime.Today.AddDays(1);
            ((DevExpress.XtraCharts.XYDiagram)chartControl1.Diagram).AxisY.VisualRange.MinValue = DateTime.Today;
            DrawConstantLine();
            ((PointSeriesView)chartControl1.SeriesTemplate.View).PointMarkerOptions.Size = 4;
            //((PointSeriesView)chartControl1.Series[0].View).PointMarkerOptions.BorderVisible = false;
            //chartControl1.ToolTipEnabled = DevExpress.Utils.DefaultBoolean.False;
            chartControl1.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.False;
        }


        ConstantLine beyaz;

        private void DrawConstantLine()
        {
            DateTime now = DateTime.Now;    //"Current progress"
            beyaz.AxisValue = now;
            beyaz.Name = now.ToShortTimeString();
        }
    }
}